{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9e2a3955",
   "metadata": {},
   "source": [
    "## Homework1_python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b38d752c",
   "metadata": {},
   "source": [
    "### 1.字符串:给定一个文章，找出每个单词的出现次数。例如给定下面的一篇短文，进行操作。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "343a13a8",
   "metadata": {},
   "source": [
    "One is always on a strange road, watching strange scenery and listening to strange music. Then one day, you will find that the things you try hard to forget are already gone."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "445bbf74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Result:\n",
      "one 2\n",
      "is 1\n",
      "always 1\n",
      "on 1\n",
      "a 1\n",
      "strange 3\n",
      "road 1\n",
      "watching 1\n",
      "strange 3\n",
      "scenery 1\n",
      "and 1\n",
      "listening 1\n",
      "to 2\n",
      "strange 3\n",
      "music 1\n",
      "then 1\n",
      "one 2\n",
      "day 1\n",
      "you 2\n",
      "will 1\n",
      "find 1\n",
      "that 1\n",
      "the 1\n",
      "things 1\n",
      "you 2\n",
      "try 1\n",
      "hard 1\n",
      "to 2\n",
      "forget 1\n",
      "are 1\n",
      "already 1\n",
      "gone 1\n"
     ]
    }
   ],
   "source": [
    "#字符串改成小写格式方便检查\n",
    "input=\"One  is always on a strange road, watching strange scenery and listening to strange music. Then one day, you will find that the things you try hard to forget are already gone.\".lower()\n",
    "input=input.replace(\",\",\" \")\n",
    "input=input.replace(\".\",\" \")#用空格替换逗号和句号\n",
    "word=input.split()#将字符串分割存储进列表\n",
    "print(\"Result:\")\n",
    "for i in range(len(word)):\n",
    "    num=word.count(word[i])\n",
    "    print(word[i],num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dddd1b9e",
   "metadata": {},
   "source": [
    "### 2.组合:有 1、2、3、4 个数字，能组成多少个互不相同且无重复数字的三位数？都是多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b3550ca0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[123, 124, 132, 134, 142, 143, 213, 214, 231, 234, 241, 243, 312, 314, 321, 324, 341, 342, 412, 413, 421, 423, 431, 432]\n",
      "24\n"
     ]
    }
   ],
   "source": [
    "num=list()\n",
    "for i in range(1,5):\n",
    "    num1=i\n",
    "    for j in range(1,5):\n",
    "        if j==i:\n",
    "            continue\n",
    "        else:\n",
    "            num2=j\n",
    "            for k in range(1,5):\n",
    "                if k==j or k==i:\n",
    "                    continue\n",
    "                else:\n",
    "                    num3=k\n",
    "                    num.append(num1*100+num2*10+num3)\n",
    "print(num) \n",
    "print(len(num))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54c270ff",
   "metadata": {},
   "source": [
    "### 3.判断 \n",
    "\n",
    "企业发放的奖金根据利润提成。利润(I)：\n",
    "\n",
    "* 低于或等于 10 万元时，奖金可提 10%；\n",
    "* 高于 10 万元，低于 20 万元时，低于 10 万元的部分按 10%提成，高于 10 万元的部分，可提成 7.5%；\n",
    "* 20 万到 40 万之间时，高于 20 万元的部分，可提成 5%；\n",
    "* 40 万到 60 万之间时，高于 40 万元的部分，可提成 3%；\n",
    "* 60 万到 100 万之间时，高于 60 万元的部分，可提成 1.5%，\n",
    "* 高于 100 万元时， 超过 100 万元的部分按 1%提成， 从键盘输入当月利润 I\n",
    "\n",
    "求应发放奖金总数？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3069dc9c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120\n",
      "1.9900000000000002\n"
     ]
    }
   ],
   "source": [
    "profit=input()\n",
    "profit=int(profit)\n",
    "if profit<=10:\n",
    "    bonus=0.1*profit\n",
    "elif 10<profit<20:\n",
    "    bonus=0.1*10+0.075*(protfit-10)\n",
    "elif 20<=profit<40:\n",
    "    bonus=0.1*10+0.075*10+(profit-20)*0.005\n",
    "elif 40<=profit<60:\n",
    "    bonus=0.1*10+0.075*10+20*0.005+(profit-40)*0.003\n",
    "elif 60<=profit<100:\n",
    "    bonus=0.1*10+0.075*10+20*0.005+20*0.003+(profit-60)*0.0015\n",
    "else:\n",
    "    bonus=0.1*10+0.075*10+20*0.005+20*0.003+40*0.0015+(profit-100)*0.001\n",
    "print(bonus)\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c23e435",
   "metadata": {},
   "source": [
    "### 4.循环：输出9x9的乘法口诀表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "730757d9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1x1=1   \t\n",
      "1x2=2   2x2=4   \t\n",
      "1x3=3   2x3=6   3x3=9   \t\n",
      "1x4=4   2x4=8   3x4=12  4x4=16  \t\n",
      "1x5=5   2x5=10  3x5=15  4x5=20  5x5=25  \t\n",
      "1x6=6   2x6=12  3x6=18  4x6=24  5x6=30  6x6=36  \t\n",
      "1x7=7   2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49  \t\n",
      "1x8=8   2x8=16  3x8=24  4x8=32  5x8=40  6x8=48  7x8=56  8x8=64  \t\n",
      "1x9=9   2x9=18  3x9=27  4x9=36  5x9=45  6x9=54  7x9=63  8x9=72  9x9=81  \t\n"
     ]
    }
   ],
   "source": [
    "for j in range(1,10):#按行输出，i为行标，j为列标\n",
    "    num=list()\n",
    "    for i in range(1,j+1):\n",
    "        num.append(str(i)+\"x\"+str(j)+\"=\"+str(i*j))\n",
    "    for k in range(len(num)):\n",
    "        print(\"%-7s\"%num[k],end=\" \")#格式化输出，左对齐\n",
    "    print(\"\\t\")#打印完一行后初始化列表进入下一行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6433b117",
   "metadata": {},
   "source": [
    "### 5.使用while循环实现输出2-3+4-5+6.....+100的和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "01e767ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "51\n"
     ]
    }
   ],
   "source": [
    "#normal practice\n",
    "sum=0\n",
    "i=2\n",
    "while i<=100:\n",
    "    sum=sum+i*((-1)**i)\n",
    "    i+=1\n",
    "print(sum)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
